#!/bin/bash
#usage: $ ./ITGDecALL
#
# This script will take all log files (name starting with 'log_')
# and decode them.
#
# after putting them nicely in a folder here...
# ... they will also be scp'd to ktr-omega (IF IP IS STILL THE RIGHT ONE!).
#
############################################

#DECODE
# process all output log files in /home/mininet/

for file in $(ls log_*)
do
    outputFileName="decoded_txt_${file}.txt"
    outputOctaveFileName="decoded_dat_${file}.dat"

    #OLD SETUP, JUST THE BASE FILE
    ~/D-ITG/D-ITG-2.8.0-rc1/bin/ITGDec ${file} -l $outputFileName -o $outputOctaveFileName

done

# move them to a dedicated folder so scp later will work
rm -rf /home/mininet/itg-logs/
mkdir /home/mininet/itg-logs
mv /home/mininet/decoded_* /home/mininet/itg-logs


# setting for pushing testfiles to ktr-omega.local to while @ktr lab
# using 'ktr-omega.local' instead of the current ip does not work due to nameserver issues
#   set accordingly if the matlab workstation ip changes!
sshpass -p tcpip-admin ssh -oStrictHostKeyChecking=no ktr@141.13.92.12 "rm -rf Documents/MATLAB/Mininet/logs && mkdir Documents/MATLAB/Mininet/logs && exit"
sshpass -p tcpip-admin scp -oStrictHostKeyChecking=no -r /home/mininet/itg-logs/* ktr@141.13.92.12:Documents/MATLAB/Mininet/logs/

# clean up all generated log binaries
rm -rf /home/mininet/log_*
